<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiRoleRolesFieldsAloneTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_role_roles_fields_alone';

    /**
     * Run the migrations.
     * @table qii_role_roles_fields_alone
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id')->comment('ID');
            $table->unsignedInteger('user_id')->default('0')->comment('会员ID');
            $table->unsignedInteger('roles_id')->default('0')->comment('角色ID');
            $table->string('fields_id', 100)->default('')->comment('字段ID');
            $table->text('field_value')->nullable()->default(null)->comment('字段值');
            $table->unsignedInteger('field_crc32')->default('0')->comment('字段值的循环冗余校验码(用于提高检索性能)');

            $table->index(["user_id", "field_crc32"], 'user_id_field_crc32');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
